<cfsetting enablecfoutputonly="Yes">

<!--- 
  /**
   * @author  auke@vanleeuwen.net
   * @version 1.0 - 2003/11/24
   * @version 1.1 - 2003/11/25 - with bCollapse as second argument
   */
--->

<cfscript>
  function dump( v )
  {
    /* scope some variables **** NEEDS TO BE DONE *** for recursion to work properly */
    var i = 1;
    var j = 1;
    var aKey = arrayNew( 1 );
    var lColumn = "";
    
    if(( arrayLen( arguments ) eq 2 ) and isBoolean( arguments[2] ))
      bCollapse = arguments[2];
    else
      bCollapse = false;

    if( not isDefined( "bInitialized" ) or not bInitialized )
    {
      /* toggle javascript */
      writeOutput( '<script type="text/javascript">
                      function toggle( source, nType ) 
                      { 
                        /* nType: 1: struct, 2:array, 3:query */ 
                        if( nType == 1 ) /* struct */ 
                        { 
                          target = source.parentNode.cells[1].style; 
                          if( target.display == "none" ) 
                          { 
                            source.style.fontStyle = "normal"; 
                            source.style.backgroundColor = "aaaaee"; 
                            target.display = ""; 
                          } 
                          else 
                          { 
                            source.style.fontStyle = "italic"; 
                            source.style.backgroundColor = "silver"; 
                            target.display = "none"; 
                          } 
                        } 
                        else if( nType == 2 ) /* array */ 
                        { 
                          target = source.parentNode.cells[1].style; 
                          if( target.display == "none" ) 
                          { 
                            source.style.fontStyle = "normal"; 
                            source.style.backgroundColor = "cceecc"; 
                            target.display = ""; 
                          } 
                          else 
                          { 
                            source.style.fontStyle = "italic"; 
                            source.style.backgroundColor = "silver"; 
                            target.display = "none"; 
                          } 
                        } 
                        else /* query */ 
                        { 
                          /* figure out which column this is (in the table) */ 
                          for( i = 0; i < source.parentNode.cells.length; i++ ) 
                          { 
                            if( source.parentNode.cells[i] == source ) 
                              index = i; 
                          } 
                          /* now collapse all those cells */ 
                          for( i = 1; i < source.parentNode.parentNode.rows.length; i++ ) 
                          { 
                            target = source.parentNode.parentNode.rows[i].cells[index].style; 
                            if( target.fontSize == "0px" ) 
                            { 
                              source.style.fontStyle = "normal"; 
                              source.style.backgroundColor = "eeaaaa"; 
                              target.fontSize = "12px"; 
                            } 
                            else 
                            { 
                              source.style.fontStyle = "italic"; 
                              source.style.backgroundColor = "silver"; 
                              target.fontSize = "0px"; 
                            } 
                          } 
                        } 
                      } 
                    </sc' & 'ript>' );
      /* stylesheet */
      writeOutput( '<style>
                      *
                      { 
                        font-size : 12px; 
                        font-family : Verdana; 
                      } 
                      
                      th 
                      { 
                        text-align : left; 
                        vertical-align : top; 
                        font-weight : normal; 
                        cursor: pointer; 
                      } 
                      /* wddx stylesheet */ 
                      .wddx 
                      { 
                        font-family : Courier New; 
                        color : green; 
                      } 
                      /* simplevalue stylesheet */ 
                      .simpleValue 
                      { 
                        color : black; 
                      } 
                      /* structure stylesheet */ 
                      .struct 
                      { 
                        border : 1px solid blue; 
                      } 
                      th.struct 
                      { 
                        background : ##aaaaee; 
                      } 
                      /* query stylesheet */ 
                      .query 
                      { 
                        border : 1px solid red; 
                      } 
                      th.query 
                      { 
                        background : ##eeaaaa; 
                      } 
                      /* array stylesheet */ 
                      .array 
                      { 
                        border : 1px solid green; 
                      } 
                      th.array 
                      { 
                        background : ##cceecc; 
                      } 
                    </style>' );
      bInitialized = true;
    }
    
    /*********************************************************************************
    *                                     WDDX                                       *
    *********************************************************************************/
    if( isSimpleValue( v ) and isWddx( v ))
    {
      writeOutput( '<span class="wddx">' & HTMLEditFormat( v ) & '</span>' );
    }
    /*********************************************************************************
    *                                 SIMPLE VALUE                                   *
    *********************************************************************************/
    else if( isSimpleValue( v ))
    {
      writeOutput( '<span class="simpleValue">' & HTMLEditFormat( v ) & '</span>' );
    }
    /*********************************************************************************
    *                                     QUERY                                      *
    *********************************************************************************/
    else if( isQuery( v ))
    {
      lColumn = v.columnList;
      writeOutput( '<table class="query" cellpadding="2" cellspacing="0">' );
      writeOutput( '<tr>' );
      /* columnNames */
      for( i = 1; i lte listLen( lColumn ); i = i + 1 )
      {
        writeOutput( '<th class="query" onclick="toggle( this, 3 );"#iif( bCollapse, de( ' style="background: silver; font-style: italic;"' ), de( '' ))#>' & HTMLEditFormat( listGetAt( lColumn, i )) & '</th>' );
      }
      writeOutput( '</tr>' );
      /* data */
      for( i = 1; i lte v.recordCount; i = i + 1 )
      {
        writeOutput( '<tr>' );
        for( j = 1; j lte listLen( lColumn ); j = j + 1 )
        {
          writeOutput( '<td class="query"#iif( bCollapse, de( ' style="font-size: 0px;"' ), de( '' ))#>' & HTMLEditFormat( v[listGetAt( lColumn, j )][i] ) & '</td>' );
        }
        writeOutput( '</tr>' );
      }
      writeOutput( '</table>' );
    }
    /*********************************************************************************
    *                                     STRUCTURE                                  *
    *********************************************************************************/
    else if( isStruct( v ))
    {
      writeOutput( '<table class="struct" cellpadding="2" cellspacing="0">' );
      if( structIsEmpty( v ))
      {
        writeOutput( '<tr><td class="struct">[empty struct]</td></tr>' );
      }
      else
      {
        aKey = structKeyArray( v );
        arraySort( aKey, 'textnocase' );
        for( i = 1; i lte arrayLen( aKey ); i = i + 1 )
        {
          writeOutput( '<tr>' );
          writeOutput( '<th class="struct" onclick="toggle( this, 1 );"#iif( bCollapse, de( ' style="background: silver; font-style: italic;"' ), de( '' ))#>' & aKey[i] & '</th>' );
          writeOutput( '<td class="struct"#iif( bCollapse, de( ' style="display: none;"' ), de( '' ))#>' );
          /* recursion call */
          dump( v[#aKey[i]#], bCollapse );
          writeOutput( '</td></tr>' );
        }
      }
      writeOutput( '</table>' );
    }
    /*********************************************************************************
    *                                     ARRAY                                      *
    *********************************************************************************/
    else if( isArray( v ))
    {
      writeOutput( '<table class="array" cellpadding="2" cellspacing="0">' );
      if( arrayIsEmpty( v ))
      {
        writeOutput( '<tr><td class="array">[empty array]</td></tr>' );
      }
      else
      {
        for( i = 1; i lte arrayLen( v ); i = i + 1 )
        {
          writeOutput( '<tr>' );
          writeOutput( '<th class="array" onclick="toggle( this, 2 );"#iif( bCollapse, de( ' style="background: silver; font-style: italic;"' ), de( '' ))#>' & i & '</th>' );
          writeOutput( '<td class="array"#iif( bCollapse, de( ' style="display: none;"' ), de( '' ))#>' );
          /* recursion call */
          dump( v[i], bCollapse );
          writeOutput( '</td></tr>' );
        }
      }
      writeOutput( '</table>' );
    }
    /*********************************************************************************
    *                                     MX OBJECTS?                                *
    *********************************************************************************/
    else
    {
      writeOutput( '[unable to dump this type of variable]<br>[not implemented yet]' );
    }
  }
  
  /* Copy to the request scope, so it's visible throughout the whole application */
  request.udf.dump = dump;
</cfscript>

<cfsetting enablecfoutputonly="No">